package com.yfkj.receiver.mq.rabbitmq;

import com.rabbitmq.client.Channel;
import com.yfkj.receiver.mq.service.ConsumeService;
import com.yfkj.support.constans.MessageQueuePipeline;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * rabbitMQ队列监听
 */
@Component
@ConditionalOnProperty(name = "yfkj.mq.pipeline", havingValue = MessageQueuePipeline.RABBIT_MQ)
public class RabbitMqReceiver {

    @Autowired
    ConsumeService consumeService;


    @RabbitListener(queues = {RabbitMqConstant.testQueue})
    @RabbitHandler
    public void testQueueConsumer(String message, Message mqMessage, Channel channel){
        /**
         * 消费队列消息
         */
        consumeService.consumeTestMessage("收到RabbitMQ消息："+message);
    }
}
